﻿using MaterialDesignThemes.Wpf;

using PLCS.App.Shared.Service.Dialog;

namespace PLCS.App.Shared.ViewModels;

public abstract class HostDialogViewModel : BaseViewModel, IHostDialogAware
{
    public string Title { get; set; }

    public string IdentifierName { get; set; }

    public DelegateCommand SaveCommand { get; }

    public DelegateCommand CancelCommand { get; }
    private bool _savebuttonIsEnabled = true;

    public bool SavebuttonIsEnabled
    {
        get { return _savebuttonIsEnabled; }
        set { SetProperty(ref _savebuttonIsEnabled, value); }
    }

    public HostDialogViewModel()
    {
        SaveCommand = new DelegateCommand(Save);
        CancelCommand = new DelegateCommand(Cancel);
    }

    protected virtual void Cancel()
    {
        DialogHost.Close(IdentifierName, new DialogResult(ButtonResult.No));
    }

    protected virtual void Save()
    {
        DialogHost.Close(IdentifierName, new DialogResult(ButtonResult.OK));
    }

    protected virtual void Save(object value)
    {
        DialogParameters param = new()
        {
            { "Value", value }
        };

        DialogHost.Close(IdentifierName, new DialogResult(ButtonResult.OK, param));
    }

    protected virtual void Save(DialogParameters param)
    {
        DialogHost.Close(IdentifierName, new DialogResult(ButtonResult.OK, param));
    }

    public abstract void OnDialogOpened(IDialogParameters parameters);
}